export default {
  name: 'checkCreative',
  props:{
    campaign_list:'',
    value:''
  },
  data () {
  	 return {
        size:'',
        sizeList:[{
              value:'',
              label:'全部尺寸'
          }
        ],
        rank:'',
        rankList:[{
              value: '',
              label: '全部等级'
            },
            {
              value: '1',
              label: '一级'
            },
            {
              value: '2',
              label: '二级'
            },
            {
              value: '3',
              label: '三级'
            },
            {
              value: '4',
              label: '四级'
            },
            {
              value: '10',
              label: '十级'
            },
            {
              value: '99',
              label: '未分级'
            }
        ],
        status:'',
        statusList:[
            {
              value: '',
              label: '全部状态'
            },
            {
              value:'-4,-1,0',
              label:'待审核'
            },
            {
              value:'1',
              label:'审核通过'
            },
            {
              value:'-2,-5,-9',
              label:'审核拒绝'
            }
        ],
        creativeName:'',
        checkboxModalAll:false,
        loading:false,
        gridData:[],
        currentPageModel:1,
        total_count_modl:0,
        creativeSource:null,
        checkboxModal:[]
     }
  },
  // computed:{
  //   campaign_list(){
  //     return this.campaign_list
  //   }
  // },
  mounted() {
      this.getCreative();
  },
  watch:{
    size(val){
      this.getCreative();
    },
    rank(val){
      this.getCreative();
    },
    status(){
      this.getCreative();
    },
    creativeName(){
      this.getCreative();
    },
    checkboxModalAll(val){
        this.checkboxModal=[];
        if(val){
          for (let index = 0; index < this.gridData.length; index++) {
              const element = this.gridData[index];
              this.checkboxModal.push(element.id);
          }
        }
    },
    checkboxModal(val){
        this.$emit('input',this.checkboxModal);
    }
  },
  methods:{
    pagechangeModel(val){
      this.currentPageModel=val;
      this.getCreative(val);
    },
    getCreative(page){
        // if(this.checkbox.length<=0){
        //     this.dialogTableVisible=false;
        //     this.$message.error('请先选择计划信息');
        //     return;
        // }
        this.loading=true;
        const loading = this.$loading({
          target:'.creative-check-box',
          lock: true,
          text: '数据获取中....',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)',
          customClass:'lodding'
        });
        let _this=this;
        let page_num=page || 1;
        this.gridData=[];
        this.checkboxModalAll=false;
        this.checkboxModal=[];
        let data={
          "page_num": page_num,
          "page_size": 20,
          "campaign_id":this.campaign_list,
           "size_list": this.size_list==""?undefined:([this.size]),
          "creative_level":this.rank==""?undefined:(this.rank),
          "audit_status_list":this.status==''?undefined:([this.status]),
          "name": this.creativeName==''?undefined:(this.creativeName.replace(/^\s+|\s+$/g,""))
        };
        if(typeof this.creativeSource=='function'){
                this.creativeSource();//取消请求
        }
        this.$http({
          method: 'post',
          url: '/zuanzhan/creative/batch',
          data: data,
          cancelToken: new this.$http.CancelToken(c=>{
            this.creativeSource = c;
          })
        }).then((data) => {
          this.loading=false;
          loading.close();
          if(this.sizeList.length<=1){
            for (let index = 0; index < data.data.data.size_list.length; index++) {
                const element = data.data.data.size_list[index];
                this.sizeList.push({
                  value:element,
                  label:element
              })
            }
          }
          this.gridData = data.data.data.creatives;
          this.total_count_modl = data.data.data.total_count;
        })
        .catch(function (error) {
          _this.loading=false;
          loading.close();
          console.log(error);
        });
    }
  }
}